package com.ruoyi.system;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AhhcDepartments;
import com.ruoyi.system.service.IAhhcDepartmentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科室表Controller
 *
 * @author ruoyi
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/system/departments")
public class AhhcDepartmentsController extends BaseController
{
    @Autowired
    private IAhhcDepartmentsService ahhcDepartmentsService;

    /**
     * 查询科室表列表
     */
    @PreAuthorize("@ss.hasPermi('system:departments:list')")
    @GetMapping("/list")
    public TableDataInfo list(AhhcDepartments ahhcDepartments)
    {
        startPage();
        List<AhhcDepartments> list = ahhcDepartmentsService.selectAhhcDepartmentsList(ahhcDepartments);
        return getDataTable(list);
    }

    /**
     * 导出科室表列表
     */
    @PreAuthorize("@ss.hasPermi('system:departments:export')")
    @Log(title = "科室表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AhhcDepartments ahhcDepartments)
    {
        List<AhhcDepartments> list = ahhcDepartmentsService.selectAhhcDepartmentsList(ahhcDepartments);
        ExcelUtil<AhhcDepartments> util = new ExcelUtil<AhhcDepartments>(AhhcDepartments.class);
        util.exportExcel(response, list, "科室表数据");
    }

    /**
     * 获取科室表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:departments:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ahhcDepartmentsService.selectAhhcDepartmentsById(id));
    }

    /**
     * 新增科室表
     */
    @PreAuthorize("@ss.hasPermi('system:departments:add')")
    @Log(title = "科室表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AhhcDepartments ahhcDepartments)
    {
        //雪花算法生成id
        ahhcDepartments.setId(UUID.randomUUID().toString().replace("-", ""));


        return toAjax(ahhcDepartmentsService.insertAhhcDepartments(ahhcDepartments));
    }

    /**
     * 修改科室表
     */
    @PreAuthorize("@ss.hasPermi('system:departments:edit')")
    @Log(title = "科室表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AhhcDepartments ahhcDepartments)
    {
        return toAjax(ahhcDepartmentsService.updateAhhcDepartments(ahhcDepartments));
    }

    /**
     * 删除科室表
     */
    @PreAuthorize("@ss.hasPermi('system:departments:remove')")
    @Log(title = "科室表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ahhcDepartmentsService.deleteAhhcDepartmentsByIds(ids));
    }
}
